import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const constRoutesM = [
    {
        path: "/",
        redirect: "login"
    },
    {
        path: "/login",
        name: "login",
        component: () => import("@/views/mobile/login.vue")
    },
];
const constRoutesPc = [
    {
        path: "/",
        redirect: "login"
    },
    {
        path: "/login",
        name: "login",
        component: () => import("@/views/pc/login.vue")
    },
];
var routes = [];
let Adaptive =
  /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i;
if (navigator.userAgent.match(Adaptive)) {
    
  routes = constRoutesM;
} else {
  routes = constRoutesPc;
}

console.log(routes,'routes')
const router = new VueRouter({
    mode: "history",
    routes: routes,
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition;
        } else {
            return { x: 0, y: 0 };
        }
    }
});
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location, resolve, reject) {
    if (resolve || reject) return originalPush.call(this, location, resolve, reject);
    return originalPush.call(this, location).catch(e => {
        // console.log(e);
    });
};
export default router;
